SONARJAVA-6406 Create rule S8714 - Use assertThrows/assertDoesNotThrow instead of try-catch with fail()#5642
SONARJAVA-6406 Create rule S8714 - Use assertThrows/assertDoesNotThrow instead of try-catch with fail()#5642rombirli wants to merge 16 commits into
Conversation
Agentic Analysis: Early ResultsAgentic Analysis and Context Augmentation are available on your project. Here are some issues that could have been prevented. Follow the links to learn how to put them into action. 17 issue(s) found across 1 file(s):
Analyzed by SonarQube Agentic Analysis in 13.4 s |
✅ Code review updated (blocking issues remain unresolved).
319c62c to
0cb3ee1
Compare
|
Code Review ✅ Approved 4 resolved / 4 findingsImplements rule S8714 to replace try-catch blocks with JUnit assertion methods. Resolved initial compilation errors and corrected the exception assertion logic to ensure accurate reporting. ✅ 4 resolved✅ Bug: Test uses no-op check so verifyIssues() will always fail
✅ Bug: Method doesBlockFail does not exist; code won't compile
✅ Bug: Wrong suggestion: try-block fail() should recommend assertThrows
✅ Bug: Autoscan shows rule S8714 finds zero true positives (33 false negatives)
Tip Comment OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |




Summary by Gitar
S8714to detecttry-catchblocks usingfail()for exception testing, recommendingassertThrowsorassertDoesNotThrowinstead.AssertThrowsInsteadOfTryCatchFailCheckSample.javafor validation.UnitTestUtils.isTryCatchFailtodoesBlockFailto accommodate the new rule's detection logic.java-S8714.jsonto ruling tests and updatedSonar_way_profile.jsonandSonar_agentic_AI_profile.jsonto include the new rule.diff_S8714.jsonto autoscan resources and verified test coverage viaJavaAgenticWayProfileTest.This will update automatically on new commits.